package net.zdreamer.geracomium.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.geracomium.R;

import net.zdreamer.geracomium.entity.GridImageInfos.GridImageInfo;
import net.zdreamer.geracomium.ui.more.FoodDetailsActivity;
import net.zdreamer.geracomium.utils.tools_utils.ViewHolder;

import java.util.List;

public class GridViewAdapter extends MyBaseAdapter<GridImageInfo> {
	private List<GridImageInfo> list;
	public static boolean[] ischoose;
	private String where;
	private Context mcontext;

	public GridViewAdapter(Context context, List<GridImageInfo> list, int res,
			String where) {
		super(context, list, res);
		this.list = list;
		this.where = where;
		this.mcontext = context;
		ischoose = new boolean[list.size()];
		for (boolean b : ischoose) {
			b = false;
		}
	}

	@Override
	protected View getView(final int position, View convertView,
			ViewGroup parent, GridImageInfo value) {
		ImageView itemimg = ViewHolder.get(convertView, R.id.item_imge);
		ImageView specific = ViewHolder.get(convertView, R.id.item_specific);
		final ImageView itemisChoose = ViewHolder.get(convertView,
				R.id.isChoose_item);
        itemimg.setImageResource((int)value.imageURL.get(position).get("image"));
      // // System.out.println();
		if (where.equals("serve")) {
			specific.setImageResource(R.drawable.selector_xiangqing);
		} else if (where.equals("ording")) {
			specific.setImageResource(R.drawable.selector_delete);
			itemimg.setEnabled(false);
		}
		itemimg.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if (!ischoose[position]) {
					ischoose[position] = true;
					itemisChoose.setVisibility(View.VISIBLE);
				} else {
					ischoose[position] = false;
					itemisChoose.setVisibility(View.INVISIBLE);
				}

			}
		});
		specific.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (where.equals("serve")) {
					Intent intent = new Intent(mcontext,
							FoodDetailsActivity.class);
					mcontext.startActivity(intent);
				}
			}
		});
		return convertView;
	}

}
